/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.iss.examsys.ejb;

import com.iss.examsys.entity.StudentExamStatus;
import java.util.ArrayList;
import java.util.HashMap;
import javax.ejb.Singleton;

/**
 *
 * @author User
 */
@Singleton
public class StudentExamStatusBean {

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
    private ArrayList<StudentExamStatus> studentsExamStatuses = new ArrayList<StudentExamStatus>();

    public ArrayList<StudentExamStatus> getStudentsExamStatuses() {
        return studentsExamStatuses;
    }

    public void setStudentsExamStatuses(ArrayList<StudentExamStatus> studentsExamStatuses) {
        this.studentsExamStatuses = studentsExamStatuses;
    }
    
    public void add(StudentExamStatus studentExamStatus){
        if(!studentsExamStatuses.contains(studentExamStatus)){
             studentsExamStatuses.add(studentExamStatus);
        }else{
            updateStudentExamStatus(studentExamStatus);
        }
    }
    
    private void updateStudentExamStatus(StudentExamStatus studentExamStatus){
        for(int i=0;i<studentsExamStatuses.size();i++){
           StudentExamStatus recordStudentsExamStatuse = studentsExamStatuses.get(i);
           
           if(recordStudentsExamStatuse.equals(studentExamStatus)){
               recordStudentsExamStatuse.setAnsweredQuestions(studentExamStatus.getAnsweredQuestions());
               recordStudentsExamStatuse.setStudentStatus(studentExamStatus.getStudentStatus());
               break;
           }
        
        }
    }
    
    public void clearStudentExamStatus(){
        studentsExamStatuses = new ArrayList<StudentExamStatus>();
    }
    
}
